<template>
	<view class="container pbsafe_56">
		<view class="bc_fff">
			<u-cell-group>
				<u-cell>
					<view slot="title" class="u-slot-title">
						<text class="ib width_108">物流公司名称</text>
						<u--input v-model="params.name" placeholderStyle="color: #999;" maxlength="20"
							placeholder="请输入姓名" border="none" />
					</view>
				</u-cell>
				<u-cell>
					<view slot="title" class="u-slot-title">
						<text class="ib width_108">联系电话</text>
						<u--input v-model="params.mobile" placeholderStyle="color: #999;" maxlength="11"
							placeholder="请输入联系电话" type="number" border="none" />
					</view>
				</u-cell>
				<u-cell>
					<view slot="title" class="u-slot-title">
						<text class="ib width_108">详细地址</text>
						<u--input v-model="params.address" placeholderStyle="color: #999;" maxlength="50"
							placeholder="请填写具体地址（选填）" border="none" />
					</view>
				</u-cell>
			</u-cell-group>
		</view>
		<view class="pf b_0 l_0 r_0 pt_8 pbsafe_8 plr_16 bc_fff">
			<button class="custom_btn primary w100 lh_40 br_56 fz_14 fb" @click="handleAdd">立即保存</button>
		</view>
	</view>
</template>

<script>
	import api from '@/service/config/api.js'
	import dataMixin from '@/mixins/data.js'
	export default {
		mixins: [dataMixin],
		data() {
			return {
				params: {
					name: '', //物流公司名称
					mobile: '', //	联系电话
					address: '' // 详细地址
				},
				id: null,
				updateUrl: '/user/api/LogisticsManage'
			};
		},
		onLoad(options) {
			if (options.id) {
				uni.setNavigationBarTitle({
					title: '编辑物流'
				})
				this.id = options.id
				this.getDetail()
			}
		},
		methods: {
			getDetail() {
				this.$utils.loading()
				api.get('/user/api/LogisticsManage/' + this.id).then(res => {
					if (res.data)
						this.params = res.data
				})
			},
			handleAdd() {
				if (!this.params.name) {
					return this.$utils.showToast('请填写物流公司名称')
				}
				if (!this.params.mobile) {
					return this.$utils.showToast('请填写联系电话')
				}
				if (this.id) {
					return this.updateData(1)
				}
				this.$utils.loading()
				api.post('/user/api/LogisticsManage', {
					...this.params
				}).then(res => {
					uni.hideLoading()
					uni.navigateBack()
					console.log(res)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	/deep/.u-slot-title {
		display: table;

		text {
			display: table-cell;
		}
	}

	.area_placholder {
		/deep/picker {
			color: #999 !important;
		}
	}
</style>